﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using ARR.Entities;
using System.Threading;
using ARR.UI.EnvoyImporterService;
using ARR.UI.ArticlesService;
using DDF.Entity;
using ARR.UI.Models;
using System.ServiceModel;
using System.Windows;
using ARR.Shared;
using ARR.UI.AuditTrailsService;
using ARR.UI.CategoriesService;

namespace ARR.UI.Models
{
    public interface ISalesImporterModel : IModelBase
    {
        List<ImporterResult> Results { get; set; }

        void SaveAuditTrails(List<AuditTrail> auditTrails);

        ObservableCollection<TempArticleSale> TempArticleSales { get; set; }

        ObservableCollection<TempArticleSale> TempArticleSalesCache { get; set; }
    }

    public class SalesImporterModel : ModelBase, ISalesImporterModel
    {
        public SalesImporterModel()
        {
            this.Results = new List<ImporterResult>();
            this.TempArticleSales = new ObservableCollection<TempArticleSale>();
            this.TempArticleSalesCache = new ObservableCollection<TempArticleSale>();
        }

        public List<ImporterResult> Results { get; set; }

        public ObservableCollection<TempArticleSale> TempArticleSales { get; set; }

        public ObservableCollection<TempArticleSale> TempArticleSalesCache { get; set; }

        public void SaveAuditTrails(List<AuditTrail> auditTrails)
        {
            AuditTrailsServiceClient service = new AuditTrailsServiceClient();

            try
            {
                service.SaveAuditTrails(auditTrails);
                service.Close();
            }
            catch
            {
                service.Abort();
                throw;
            }

        }
    }


    public class SalesImporterModellMock : MockModelBase, ISalesImporterModel
    {
        public SalesImporterModellMock()
        {
            this.Results = new List<ImporterResult>(); 
            this.TempArticleSales = new ObservableCollection<TempArticleSale>();
            this.TempArticleSalesCache = new ObservableCollection<TempArticleSale>();
        }

        public List<ImporterResult> Results { get; set; }

        public ObservableCollection<TempArticleSale> TempArticleSales { get; set; }

        public ObservableCollection<TempArticleSale> TempArticleSalesCache { get; set; }

        public void RunStep1()
        {
            Results = new List<ImporterResult>();
        }

        public void RunStep2()
        {
            Results = new List<ImporterResult>();
        }

        public void RunStep3()
        {
            Results = new List<ImporterResult>();
        }

        public void RunStep4()
        {
            Results = new List<ImporterResult>();
        }

        public void SaveAuditTrails(List<AuditTrail> auditTrails)
        {
        }
    }
}
